package com.sifang.sfuserservice.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sifang.sfuserservice.dao.UserDao;
import com.sifang.sfuserservice.dto.UserDto;
import com.sifang.sfuserservice.entity.UserEntity;
import com.sifang.sfuserservice.queue.DataDispatch;
import com.sifang.sfuserservice.service.UserService;
import com.sifang.sfuserservice.utils.SnowflakeUtil;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * 用户服务
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {

    /**
     * 用户注册提交
     * @param userDto
     */
    @Override
    public void register(UserDto userDto) {
        try {
            userDto.setId(SnowflakeUtil.snowflakeId());
            userDto.setRegisterTime(LocalDateTime.now());
            DataDispatch.USER_QUEUE.put(userDto);
        } catch (InterruptedException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
}
